﻿using Basic.WxApiRemoteModel;
using Basic.WxApiService.ApiInterface;
using Basic.WxApiService.Interface;
using Basic.WxApiService.WxModel;
using Basic.WxApiService.WxModel.Mini;
using WeDonekRpc.Client.Attr;

namespace Basic.WxApiService.WxMini
{
    [ClassLifetimeAttr(ClassLifetimeType.SingleInstance)]
    internal class WxMiniService : IWxMiniService
    {
        private static readonly WxPrower _Prower = WxPrower.开发管理与数据分析权限;
        private readonly IWxMerTokenService _TokenService;
        private readonly IMiniApi _MiniApi;
        public WxMiniService (IWxMerTokenService token,
            IMiniApi miniApi)
        {
            this._TokenService = token;
            this._MiniApi = miniApi;
        }

        public MiniEncryptKey[] GetEncryptKey (string wxAppId, string openId, string signature)
        {
            WxMerToken token = this._TokenService.GetToken(wxAppId, _Prower);
            return this._MiniApi.GetEncryptKey(token, openId, signature);
        }
        public bool CheckEncrypted (string wxAppId, string data)
        {
            WxMerToken token = this._TokenService.GetToken(wxAppId, _Prower);
            return this._MiniApi.CheckEncrypted(token, data);
        }
        public bool CheckSession (string wxAppId, string openId, string signature)
        {
            WxMerToken token = this._TokenService.GetToken(wxAppId, _Prower);
            return this._MiniApi.CheckSession(token, openId, signature);
        }
        public MiniUserPhone GetUserPhone (string wxAppId, string code)
        {
            WxMerToken token = this._TokenService.GetToken(wxAppId, _Prower);
            return this._MiniApi.GetUserPhone(token, code);
        }
    }
}
